package my.jwds.p155;

import java.util.Deque;
import java.util.LinkedList;

public class MinStack {

    public static void main(String[] args) {

        MinStack obj = new MinStack();
        long start = System.currentTimeMillis();
        System.out.println("运行时间:" + (System.currentTimeMillis() - start));
    }

    Deque<Integer> stack = new LinkedList<>();
    Deque<Integer> min = new LinkedList<>();


    public MinStack() {

    }

    public void push(int val) {
        stack.push(val);
        if (min.isEmpty()){
            min.push(val);
        }else{
            min.push(min.peek() > val?val:min.peek());
        }
    }

    public void pop() {
        stack.pop();
        min.pop();

    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return min.peek();
    }
}